#ifndef MF_FAT32_H
#define MF_FAT32_H

#include <string.h>
#include "fat_32.h"
#include "data_types.h"
#include "spirom.h"

#define MAX_FILES_PER_READ 16
#define DIR_STACK_MAX 15
#define CONTENTS_LENGTH 18



/////////////////////////

typedef struct MF_FAT32_INFO
{
	unsigned long bytesPerSector;
	unsigned long sectorPerCluster;
	unsigned long reservedSectorCount;
	unsigned long rootCluster;
	unsigned long firstDataSector;
	unsigned long FAT_Begin_Cluster;
	
}MF_FAT32_INFO;

typedef struct MF_FileInfo
{
	char name[50];
	char tagTitle[50];
	char tagAuthor[50];
	unsigned short directoryLevel;
	unsigned long clusterOffset;
	char used;
	char isFolder;
	char isFile;
	
	struct MF_FileInfo *parentDir;
}MF_FileInfo;

typedef struct MF_FAT32_Filesystem
{
	MF_FAT32_INFO filesystemInfo;
	
	MF_FileInfo currDirectory;
	MF_FileInfo dirStack[DIR_STACK_MAX]; //Directory Stack
	MF_FileInfo dirContents[CONTENTS_LENGTH]; //(16 fileInfo's, 1 EOD)
	
	char currSector;  //References sector number of current Directory Info
	char currStackNo; //References depth of directory Stack
	char numContents;
}MF_FAT32_Filesystem;

//////////////////////////

int FAT_Begin(MF_FAT32_Filesystem *fs);
unsigned long GetVolumeIDData();
int changeContext(MF_FAT32_Filesystem *fs, MF_FileInfo *toRead);
int readDirectoryInfo(MF_FAT32_Filesystem *fs, unsigned long depth);
unsigned long findCluster(MF_FAT32_Filesystem *fs, unsigned long clusterNo, int depth);
unsigned long combineInformation(unsigned char toCombine[], unsigned short len);
int getSongData(MF_FAT32_Filesystem *fs, unsigned long clusterNo, char *title, int titleLen, char *author, int authLen);
int loadSong(MF_FAT32_Filesystem *fs, unsigned long clusterNo, unsigned long finalBuff[], Uint16 lenOfBuff);//, char *title, int titleLen, char *author, int authLen, int *instrument);


#endif
